<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<div class="modal" id="addBankCardDialog">
	<input type="hidden" name="id" id="id">
	<div class="modal-dialog">
		
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="closeBankCardDialog()">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title">新增银行卡</h4>
			</div>
			<div class="form-horizontal">
				<div class="modal-body" id="addBankCardForm">
				<!-- 银行编号 bankChannelNo -->
				<input type="hidden" name="bankChannelNo" id="bankChannelNo">
					<div class="form-group">
							<label for="inputName" class="col-sm-3 control-label">开户银行</label>
							<div class="col-sm-7">
								<input type="text" class="form-control"  disabled  id="bankName" name="bankName" value="" />
							</div>
							<div class="col-sm-2">
								<button type="button" class="btn btn-default" id="add_searchBankInfoBtn"><i class="fa fa-search"></i></button>
							</div>
					</div>
					<div class="form-group">
						<label for="inputName" class="col-sm-3 control-label">银行账户类型</label>
						<div class="col-sm-7">
							<select class="form-control" id="bankAccountType" name="bankAccountType">
								<option value="">账户类型</option>
								<option value="PUBLIC_ACCOUNT">对公账户</option>
								<option value="PRIVATE_DEBIT_ACCOUNT">对私账户</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label for="inputName" class="col-sm-3 control-label">银行开户名</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" id="bankAccountName" name="bankAccountName" value="" />
						</div>
					</div>
					<div class="form-group">
						<label for="inputName" class="col-sm-3 control-label">银行账号</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" id="bankAccountNo" name="bankAccountNo" value="" />
						</div>
					</div>
					<div class="form-group">
						<label for="inputName" class="col-sm-3 control-label">证件类型</label>
						<div class="col-sm-7">
							<select class="form-control" id="cardType" name="cardType">
								<option value="">证件类型</option>
								<option value="IDENTITY">身份证</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label for="inputName" class="col-sm-3 control-label">证件号码</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" id="cardNo" name="cardNo" value="" />
						</div>
					</div>
					<div class="form-group">
						<label for="inputName" class="col-sm-3 control-label">开户手机号</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" id="mobileNo" name="mobileNo" value="" />
						</div>
					</div>
					<div class="form-group">
						<label for="inputName" class="col-sm-3 control-label">开户详细地址</label>
						<div class="col-sm-7">
							<input type="text" class="form-control" id="street" name="street" value="" />
						</div>
					</div>
					<div class="form-group">
						<label for="inputName" class="col-sm-3 control-label">平台手机号</label>
						<div class="col-sm-5">
							<input type="text" class="form-control" id="mobile" name="mobile" value="" />
						</div>
						<button class="col-sm-2 btn btn-info" id="setCode" onclick="">短信验证</button>
					</div>
					<div class="form-group" id="msg_code">
						<label for="inputName" class="col-sm-3 control-label">验证码</label>
						<div class="col-sm-3">
							<input type="text" class="form-control" id="code" name="code" value="" />
						</div>
					</div>
					 
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default pull-left" data-dismiss="modal" onclick="closeBankCardDialog()">关 闭</button>
					<button type="submit" class="btn btn-primary" id="addBankCard" onclick="addBankCard">确 认</button>
				</div>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>
<!-- /.modal -->


<script>


/*添加银行卡事件*/
$("#addBankCard").on("click",function(){
	addBankCard();
});


function addBankCard(){
	var bankChannelNo =  $('#addBankCardForm  #bankChannelNo').val();
	var bankName = $('#addBankCardForm  #bankName').val();
	var bankAccountType = $('#addBankCardForm  #bankAccountType').val();
	var bankAccountName = $('#addBankCardForm  #bankAccountName').val();
	var bankAccountNo = $('#addBankCardForm  #bankAccountNo').val();
	var cardType = $('#addBankCardForm  #cardType').val();
	var cardNo = $('#addBankCardForm  #cardNo').val();
	var mobileNo = $('#addBankCardForm  #mobileNo').val();
	var mobile = $('#addBankCardForm  #mobile').val();
	var code = $('#addBankCardForm  #code').val();
	var street = $('#addBankCardForm  #street').val();
	if(bankName == null || $.trim(bankName) == ""){
		alertMsg("请选择银行名称","danger");
	}else if(bankChannelNo == null || $.trim(bankChannelNo) == ""){
		alertMsg("获取银行编号失败","danger");
	}else if(bankAccountType == null || $.trim(bankAccountType) == ""){
		alertMsg("请输入银行账户类型","danger");
	}else if(bankAccountName == null || $.trim(bankAccountName) == ""){
		alertMsg("请输入银行开户名","danger");
	}else if(bankAccountNo == null || $.trim(bankAccountNo) == ""){
		alertMsg("请输入银行账户","danger");
	}else if(cardType == null || $.trim(cardType) == ""){
		alertMsg("请输入证件类型","danger");
	}else if(cardNo == null || $.trim(cardNo) == ""){
		alertMsg("请输入证件号码","danger");
	}else if(mobileNo == null || $.trim(mobileNo) == ""){
		alertMsg("请输入开户手机号","danger");
	}else if(mobile == null || $.trim(mobile) == ""){
		alertMsg("请输入平台手机号","danger");
	}else if(code == null || $.trim(code) == ""){
		alertMsg("请输入验证码","danger");
	}else if(street == null || $.trim(street) == ""){
		alertMsg("请输入详细地址","danger");
	}else{
		$.ajax({
			type : "POST",
			data : {
				"bankName" : bankName,
				"bankChannelNo" : bankChannelNo,
				"bankAccountNo" : bankAccountNo,
				"bankAccountType" : bankAccountType,
				"bankAccountName" : bankAccountName,
				"cardType" : cardType,
				"cardNo" : cardNo,
				"mobileNo" : mobileNo,
				"mobile" : mobile,
				"code" : code,
				"street" : street
			},
			dataType : 'json',
			url : "${baseURL }/merchant/bank/add",
			//请求成功完成后要执行的方法  
			success : function(result) {
				debugger;
				if(result.code == 0){
					alertMsg(result.msg,"danger");
					$("#addBankCardDialog").hide();
					closeBankCardDialog();
					/* window.location.reload(); */
					searchCard();
				}else{
					alertMsg(result.msg,"danger");
				}
			},
			error : function() {
				alertMsg("系统异常！","danger");
			}
		});
	}
}

  $(function () {
    var setCodeinterval;
    $("#addBankCardDialog #setCode").on("click",function(){
    	var that = $(this);
    	if(that.hasClass("btn-info")){
    		add_sendSms(that);
    	}
    })
  });
  
  function add_sendSms(that){
	  var mobile = $("#addBankCardForm #mobile").val();
	  if(mobile == null || $.trim(mobile) == ""){
			alertMsg("请输入手机号","danger");
			$("#addBankCardDialog #msg_code").hide();
	  }else{
		  alert(mobile);
		  $.ajax({  
		        type: "POST",
		        data:{mobile : mobile},
		        dataType : "json",
		        url: "${baseURL }/merchant/bank/sendSms",
		        success: function(result){
		        	if(result.code == '0'){
		        		alertMsg("验证码已成功发送至"+mobileNo,"success");
		        		$("#addBankCardDialog #msg_code").show();
		        		var num = 60;
		        		that.removeClass("btn-info").text(num + "s");
		        		setCodeinterval = setInterval(function(){
		        			num -- ;
		        			if(num < 0 ){
		        				that.text("重新发送").addClass("btn-info");
		        				clearInterval(setCodeinterval);
		        			}else{
		                		that.text(num + "s");
		        			}
		        		},1000)
		        	}else{
		        		alertMsg(result.msg,"danger");
		        		$("#addBankCardDialog #msg_code").hide();
		        	}
		        },  
		        error : function() {
		        	alertMsg("系统异常！","danger");
		        	$("#addBankCardDialog #msg_code").hide();
		        }   
		    });
	  }
  }
  
  function closeBankCardDialog(){
		var bankChannelNo =  $('#addBankCardForm  #bankChannelNo').val("");
		var bankName = $('#addBankCardForm  #bankName').val("");
		var bankAccountType = $('#addBankCardForm  #bankAccountType').val("");
		var bankAccountName = $('#addBankCardForm  #bankAccountName').val("");
		var bankAccountNo = $('#addBankCardForm  #bankAccountNo').val("");
		var cardType = $('#addBankCardForm  #cardType').val("");
		var cardNo = $('#addBankCardForm  #cardNo').val("");
		var mobileNo = $('#addBankCardForm  #mobileNo').val("");
		var mobile = $('#addBankCardForm  #mobile').val("");
		var code = $('#addBankCardForm  #code').val("");
		var street = $('#addBankCardForm  #street').val("");
 }

</script>